Ext.define('Admin.view.salary.SalaryPanel', {
    extend: 'Ext.grid.Panel',
    xtype: 'salaryPanel',
    controller: 'salaryController',

    requires: [
        'Ext.grid.filters.Filters',
        'Ext.grid.plugin.Exporter',
       	'Ext.selection.CheckboxModel'
    ],

    title: '绩效',
    	
    bind:'{salaryDataList}',
 //   store: 'BigData',
    columnLines: true,
    multiColumnSort: true,

    // We do not need automatic height synching.
    syncRowHeight: false,

    features: [{
        ftype : 'groupingsummary',
        groupHeaderTpl : '{name}',
        hideGroupedHeader : false,
        enableGroupingMenu : false
    }, {
        ftype: 'summary',
        dock: 'bottom'
    }],

  //  layout: 'border',
//    split: true,

    lockedGridConfig: {
        title: 'Employees',
        header: false,
        collapsible: true,
        width: 325,
        minWidth: 290,
        forceFit: true
    },

    selModel: {
        type: 'checkboxmodel',
        checkOnly: true
    },

    listeners: {
        headermenucreate: 'onHeaderMenuCreate',
        // this event notifies us when the document was saved
        documentsave: 'onDocumentSave',
        beforedocumentsave: 'onBeforeDocumentSave'
    },

    columns:[{
        xtype: 'rownumberer',
        width: 40,
        sortable: false,
        locked: true
    }, {
        text: 'Id',
        sortable: true,
        dataIndex: 'employee.id',
        groupable: false,
        width: 80,
        locked: true,
        editRenderer: 'bold'
    }, {
        text: 'Name (Filter)',
        dataIndex: 'employee.empName',
     //   sortable: true,
     //   sorter: {
    //        sorterFn: 'nameSorter' // set controller
     //   },

        width: 140,
        groupable: false,

        layout: 'hbox',
        locked: true,
  //      renderer: 'concatNames',
        editor: {
            xtype: 'textfield'
        },
        items: {
            xtype: 'textfield',
            reference: 'nameFilterField',
            flex : 1,
            margin: 2,
            enableKeyEvents: true
				        ,listeners: {
               keyup: 'onNameFilterKeyup',
                buffer: 500
        }
        }
    }, {
        text: 'Department',
        dataIndex: 'time',
        hidden: true,
        hideable: false,
        filter: {
            type: 'list'
        }
    }, {
        text: 'Attendance Managerment',
        shrinkWrap: true,
        columns: [{
            text: 'Absences',
            dataIndex: 'totalAbsence',
            width: 100,
            groupable: false,
            summaryType: 'sum',
            summaryFormatter: 'number("0")',
            filter: {

            },
            editor: {
                xtype: 'numberfield',
                decimalPrecision: 0
            }
        }, {
            text: 'holidays',
            dataIndex: 'totalVacation',
            width: null, // Size column to title text
            groupable: false,
            summaryType: 'sum',
            summaryFormatter: 'number("0")',
            filter: {

            },
            editor: {
                xtype: 'numberfield',
                decimalPrecision: 0
            }
        }, {
            text: 'Leaves',
            dataIndex: 'totalLeave',
            width: null, // Size column to title text
            groupable: false,
            summaryType: 'sum',
            summaryFormatter: 'number("0")',
            filter: {

            },
            editor: {
                xtype: 'numberfield',
                decimalPrecision: 0
            }
        }, {
            text: 'Overtimes',
            dataIndex: 'totalOvertime',
            width: null, // Size column to title text
            groupable: false,
            summaryType: 'sum',
            summaryFormatter: 'number("0")',
            filter: {

            },
            editor: {
                xtype: 'numberfield',
                decimalPrecision: 0
            }
        }]
    },{
        text: 'Rating',
        width: 100,
        sortable: true,
        dataIndex: 'rapscore',
        groupable: false,
        xtype: 'widgetcolumn',
        widget: {
            xtype: 'sparklineline'
        }
    },{
        text: 'Salary',
        width: 155,
        sortable: true,
        dataIndex: 'salary',
        align: 'right',
        formatter: 'usMoney',
        groupable: false,
        summaryType: 'average',
        summaryFormatter: 'usMoney',
        filter: {

        },
        editor: {
            xtype: 'numberfield',
            decimalPrecision: 2
        },
        exportStyle: {
            alignment: {
                horizontal: 'Right'
            },
            format: 'Currency'
        }
    }],

    viewConfig: {
        stripeRows: true
    },

  header: {
        itemPosition: 1, // after title before collapse tool
        items: [{
            ui: 'default-toolbar',
            xtype: 'button',
            text: 'Export to ...',
            menu: {
                defaults: {
                    handler: 'exportTo'
                },
                items: [{
                    text:   'Excel xlsx',
                    cfg: {
                        type: 'excel07',
                        ext: 'xlsx',
                        includeGroups: true,
                        includeSummary: true
                    }
                },{
                    text: 'Excel xml',
                    cfg: {
                        type: 'excel03',
                        ext: 'xml',
                        includeGroups: true,
                        includeSummary: true
                    }
                },{
                    text:   'CSV',
                    cfg: {
                        type: 'csv'
                    }
                },{
                    text:   'TSV',
                    cfg: {
                        type: 'tsv',
                        ext: 'csv'
                    }
                },{
                    text:   'HTML',
                    cfg: {
                        type: 'html',
                        includeGroups: true,
                        includeSummary: true
                    }
                }]
            }
        }]
    },

    plugins: [{
        ptype: 'gridfilters'
    }, {
        ptype: 'rowexpander',

        // dblclick invokes the row editor
        expandOnDblClick: false,
        rowBodyTpl: '<img src="{avatar}" height="100px" style="float:left;margin:0 10px 5px 0"><b>{name}<br></b>{dob:date}'
    }, {
        ptype: 'gridexporter'
    }]
});